package com.ruoyi.epidemic.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.epidemic.mapper.TbSuggestMapper;
import com.ruoyi.epidemic.domain.TbSuggest;
import com.ruoyi.epidemic.service.ITbSuggestService;

import javax.annotation.Resource;

/**
 * 意见Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-21
 */
@Service
public class TbSuggestServiceImpl implements ITbSuggestService {
    @Resource
    private TbSuggestMapper tbSuggestMapper;

    /**
     * 查询意见
     *
     * @param id 意见主键
     * @return 意见
     */
    @Override
    public TbSuggest selectTbSuggestById(Long id) {
        return tbSuggestMapper.selectTbSuggestById(id);
    }

    /**
     * 查询意见列表
     *
     * @param tbSuggest 意见
     * @return 意见
     */
    @Override
    public List<TbSuggest> selectTbSuggestList(TbSuggest tbSuggest) {
        return tbSuggestMapper.selectTbSuggestList(tbSuggest);
    }

    /**
     * 新增意见
     *
     * @param tbSuggest 意见
     * @return 结果
     */
    @Override
    public int insertTbSuggest(TbSuggest tbSuggest) {

        return tbSuggestMapper.insertTbSuggest(tbSuggest);
    }

    /**
     * 修改意见
     *
     * @param tbSuggest 意见
     * @return 结果
     */
    @Override
    public int updateTbSuggest(TbSuggest tbSuggest) {
        return tbSuggestMapper.updateTbSuggest(tbSuggest);
    }

    /**
     * 批量删除意见
     *
     * @param ids 需要删除的意见主键
     * @return 结果
     */
    @Override
    public int deleteTbSuggestByIds(Long[] ids) {
        return tbSuggestMapper.deleteTbSuggestByIds(ids);
    }

    /**
     * 删除意见信息
     *
     * @param id 意见主键
     * @return 结果
     */
    @Override
    public int deleteTbSuggestById(Long id) {
        return tbSuggestMapper.deleteTbSuggestById(id);
    }

    @Override
    public AjaxResult push(TbSuggest suggest) {
        if (suggest.getUserId() == null) {
            return AjaxResult.error(444, "请先登录");
        }
        suggest.setCreateTime(new Date());
        int i = tbSuggestMapper.insertTbSuggest(suggest);
        if (i > 0) {
            return AjaxResult.success("发布成功");
        } else {
            return AjaxResult.error("发布失败");
        }
    }

    @Override
    public AjaxResult getByUserId(Long userId) {
        List<TbSuggest> user_id = tbSuggestMapper.selectList(new QueryWrapper<TbSuggest>().eq("user_id", userId));
        return AjaxResult.success(user_id);
    }
}
